<template>
	<view>
		<view class="content">
			<view class="flex-row items-center input-list">
				<view class="input-list-label">姓 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 名</view>
				<input type="text" placeholder="请输入姓名" v-model="username"/>
			</view>
			<view class="flex-row items-center input-list" >
				<view class="input-list-label">电 &nbsp;话 &nbsp;号</view>
				<input type="text" placeholder="请输入电话号" v-model="phone" />
			</view>
			<view class="flex-row items-center input-list">
				<view class="input-list-label">身份证号</view>
				<input type="text" placeholder="请输入身份证号" v-model="idcardnum"/>
			</view>
			<view class="flex-row items-center input-list-idcard">
				<view class="input-list-label">省市区</view>
				<input type="text" placeholder="请输入省市区" v-model="area"/>
			</view>
		</view>
		<view class="button" @click="submit">
			提  交
		</view>
	</view>
	
</template>

<script>
	const app = getApp().globalData;
	export default {
		data() {
			return {
				username: '',
				phone: '',
				idcardnum: '',
				area: ''
			}
		},
		methods: {
			submit(){
				if(this.username == ''){
					uni.showToast({
						title: '姓名不能为空',
						icon: 'none'
					})
					return
				}
				if(this.phone == ''){
					uni.showToast({
						title: '电话号不能为空',
						icon: 'none'
					})
					return
				}
				const regex = /^1[3456789]\d{9}$/;  
				if(!regex.test(this.phone)){
					uni.showToast({
						title: '电话号格式不正确',
						icon: 'none'
					})
					return
				}
				if(this.idcardnum == ''){
					uni.showToast({
						title: '身份证号不能为空',
						icon: 'none'
					})
					return
				}
				const regex1 = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}([0-9]|X|x)$/
				if(!regex1.test(this.idcardnum)){
					uni.showToast({
						title: '身份证号格式不正确',
						icon: 'none'
					})
					return
				}
				if(this.area == ''){
					uni.showToast({
						title: '省市区不能为空',
						icon: 'none'
					})
					return
				}
				var _this = this;
				let user_id = uni.getStorageSync('userId')
				uni.request({
				  url: app.post_url + '/aijiu/api.Shop/apply',
				  //仅为示例，并非真实的接口地址
				  data: {
				   uid : user_id,
				   name: this.username,
				   card_num: this.idcardnum,
				   address: this.area,
				   phone: this.phone
				  },
				  method: 'post',
				  success(res) {
				    console.log(res);
					if(res.statusCode == 200){
						if(res.data.code == 1){
							uni.showToast({
								title: '提交成功'
							})
							setTimeout(()=> {
								uni.switchTab({
									url: '/pages/index/index'
								})
							},1000)
							
						}else {
							uni.showToast({
								title: res.data.info,
								icon: 'none',
								duration: 1000
							})
						}
					}else {
						uni.showToast({
							title: '失败',
							icon: 'none',
							duration: 1000
						})
					}
					
					
					
				  },
				  fail(err) {
				  	uni.showToast({
				  		title: '失败',
				  		icon: 'none',
				  		duration: 1000
				  	})
				  }
					  
				});
				
			}
		}
	}
</script>

<style>
	@import "@/common/css/common.css";
	@import "./franchise.css";
</style>